﻿#include "kidsprotect.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QCheckBox>
#include <QPushButton>
#include "utils.h"



QWidget *CreateCfgItem(QString icon, QString title, QString tip)
{
    QPushButton *item = new QPushButton();
    item->setStyleSheet("QPushButton{border-style:none;background: #fff; border: 0; }"
                  "QPushButton:hover {background: #fffcf8; border: 1px solid #ffe7c1; }");
    item->setFixedHeight(90);

    QLabel *labelIcon = new QLabel();
    QLabel *labelTitle = CreateCustomLabel(title, "#444444", 14);
    QLabel *labelTip = CreateCustomLabel(tip, "#777777", 12);
    QCheckBox *checkBox = new QCheckBox();

    checkBox->setStyleSheet("QCheckBox::indicator{width: 32px; height: 32px; }"
                            "QCheckBox::indicator:checked {border-image:url(:/img/100/switch-ON.png);}"
                            "QCheckBox::indicator:unchecked {border-image:url(:/img/100/switch-OFF.png);}");
    checkBox->setCursor(Qt::PointingHandCursor);

    labelIcon->setPixmap(QPixmap(icon));
    labelIcon->setFixedWidth(36);

    QHBoxLayout *layoutTop = new QHBoxLayout();
    layoutTop->addWidget(labelTitle);
    layoutTop->addStretch(1);
    layoutTop->addWidget(checkBox);

    QVBoxLayout *layoutRight = new QVBoxLayout();
    layoutRight->addStretch(1);
    layoutRight->addLayout(layoutTop);
    layoutRight->addWidget(labelTip);
    layoutRight->addStretch(1);
    layoutRight->setSpacing(2);
    layoutRight->setContentsMargins(10, 0, 0, 0);

    QHBoxLayout *layoutMain = new QHBoxLayout(item);
    layoutMain->addWidget(labelIcon);
    layoutMain->addWidget(CreateSeparator(true));
    layoutMain->addLayout(layoutRight);
    layoutMain->setContentsMargins(20, 10, 20, 10);
    layoutMain->setSpacing(10);

    return item;
}

KidsProtect::KidsProtect(QWidget *parent) : BaseChildPane(parent)
{
    m_strTitle = "访问控制";

    InitCtrl();
}

void KidsProtect::InitCtrl()
{
    QVBoxLayout *layoutTitle = new QVBoxLayout();
    layoutTitle->addWidget(CreateCustomLabel("将计算机调整为更适合访客使用的状态"));
    layoutTitle->addWidget(CreateCustomLabel("为防止访问控制配置以及其它配置被修改，推荐使用密码保护", "#777777", 14));
    layoutTitle->setSpacing(10);

    QVBoxLayout *layoutTopBtn = new QVBoxLayout();
    layoutTopBtn->addWidget(CreateCustomButton("密码保护"));
    layoutTopBtn->addStretch();

    QHBoxLayout *layoutTop = new QHBoxLayout();
    layoutTop->addLayout(layoutTitle);
    layoutTop->addStretch(1);
    layoutTop->addLayout(layoutTopBtn);

    QGridLayout *layoutCfg = new QGridLayout();
    layoutCfg->addWidget(CreateCfgItem(":/img/100/kidprotect/online.png", "上网时间段控制", "控制计算机上网的时间段或者累计的上网时长"), 0, 0, 1, 1);
    layoutCfg->addWidget(CreateCfgItem(":/img/100/kidprotect/website.png", "网站内容控制", "限制计算机访问特定类型网站"), 0, 1, 1, 1);
    layoutCfg->addWidget(CreateCfgItem(":/img/100/kidprotect/program.png", "程序执行控制", "限制指定应用程序的执行"), 1, 0, 1, 1);
    layoutCfg->addWidget(CreateCfgItem(":/img/100/kidprotect/udisk.png", "U盘使用控制", "限制未信任的U盘接入计算机"), 1, 1, 1, 1);


    QVBoxLayout *layoutMain = new QVBoxLayout(this);
    layoutMain->addLayout(layoutTop);
    layoutMain->addWidget(CreateSeparator());
    layoutMain->addLayout(layoutCfg);
    layoutMain->addStretch(1);
    layoutMain->setContentsMargins(40, 30, 40, 30);
    layoutMain->setSpacing(20);
}
